Class sjl.Vector
All Packages Class Hierarchy This Package Previous Next Index
Class sjl.Vector
java.lang.Object
|
+----sjl.Vector
- public class Vector
- extends Object
- implements ReversibleContainer, BackInsertContainer
Vector
is a kind of sequence that supports random access
iterators.
In additition it supports (amortized) constant time insert and erase
operations at the end; insert and erase in the middle take linear time.
Storage management is handled automatically.
insert
causes reallocation if the new size is greater
than the old capacity.
The iterators before the insertion point always remain valid.
Inserting a single element into a vector is linear in the distance from the
insertion point to the end of the vector. The amortized complexity over
the lifetime of a vector of inserting a single element at the end is
constant. Insertion of multiple elements into a vector with a single
call of the insert method is linear in the sum of the number of elements
plus the distance to the end of the vector.
In other words, it is mush faster to insert many elements into the middle
of a vector at once, than to do the insertion one at a time.
erase
invalidates all the iterators after the point of
the erase.
Copyright © 1996 Finn Bock
-
data
- Private.
-
Vector()
- Construct a new empty Vector.
-
Vector(ForwardIterator, ForwardIterator)
- Construct a new Vector with the contents of the range
[first,last)
.
-
Vector(int, Object)
- Construct a new Vector with an initial size of
size
elements, each element initialized to with a reference to value.
-
Vector(Vector)
- Construct a new Vector with the size and contents of another vector.
-
back()
- Return the last element in the container.
-
begin()
- Returns the iterator that represents the beginning of the vector.
-
beginGeneric()
- Returns the iterator that represents the beginning of the vector as
an untyped iterator.
-
beginRef()
- Returns a reference to the iterator that represents the beginning of
the vector.
-
capacity()
- Returns the maximum number of elements that can be stored in the vector
without reallocation.
-
empty()
- Returns
true
if the vector does not contain any elements.
-
end()
- Returns the iterator that represents the end of the vector.
-
endGeneric()
- Returns the iterator that represents the end of the vector as
an untyped iterator.
-
endRef()
- Returns a reference to the iterator that represents the end of
the vector.
-
equals(Object)
- Compare the elements in this container with the elements
in another container.
-
erase(Iterator)
- Removes the element specified by position.
-
erase(Iterator, Iterator)
- Removes the elements in the specified range.
-
flush()
- Erase all the elements in the container.
-
front()
- Return the first element in the container.
-
get(int)
- Returns the
n
th element in the container.
-
insert(Iterator, InputIterator, InputIterator)
- The elements in the range
[first,last)
are inserted
into vector at the
specified position.
-
insert(Iterator, int, Object)
- Insert n references to element into the vector at the specified position.
-
insert(Iterator, Object)
- Insert an element into the vector at the specified position.
-
max_size()
- Returns the maximum number of elements that can be stored in a vector.
-
pop_back()
- Removes the last element in vector.
-
push_back(Object)
- Add an element to the end of the vector.
-
put(int, Object)
- Set the
n
th element in the container to o.
-
rbegin()
- Returns a copy of the reverse iterator that represents the
beginning (end) of the list.
-
rbeginGeneric()
- Returns a copy of the reverse iterator that represents the
beginning (end) of the list as an untyped Iterator.
-
rend()
- Returns a copy of the iterator that represents the end (beginning)
of the list.
-
rendGeneric()
- Returns a copy of the iterator that represents the end (beginning)
of the list as an untyped Iterator.
-
size()
- Returns the number of elements stored in the vector.
-
toString()
- Returns the string representation of this vector.
data
protected Object data[]
- Private. The actual data array.
Vector
public Vector()
- Construct a new empty Vector.
Vector
public Vector(int size,
Object value)
- Construct a new Vector with an initial size of
size
elements, each element initialized to with a reference to value.
- Parameters:
- size - The size of the new vector.
- value - The initial value of each element in the vector.
Vector
public Vector(Vector vector)
- Construct a new Vector with the size and contents of another vector.
- Parameters:
- vector - The vector which is copied into the new vector.
Vector
public Vector(ForwardIterator first,
ForwardIterator last)
- Construct a new Vector with the contents of the range
[first,last)
.
- Parameters:
- first - The beginning of the range.
- last - The end of the range.
flush
public void flush()
- Erase all the elements in the container.
equals
public boolean equals(Object container)
- Compare the elements in this container with the elements
in another container.
- Returns:
-
true
is the elements match.
- Overrides:
- equals in class Object
begin
public VectorIterator begin()
- Returns the iterator that represents the beginning of the vector.
beginRef
public VectorIterator beginRef()
- Returns a reference to the iterator that represents the beginning of
the vector.
end
public VectorIterator end()
- Returns the iterator that represents the end of the vector.
endRef
public VectorIterator endRef()
- Returns a reference to the iterator that represents the end of
the vector.
beginGeneric
public ForwardIterator beginGeneric()
- Returns the iterator that represents the beginning of the vector as
an untyped iterator.
endGeneric
public ForwardIterator endGeneric()
- Returns the iterator that represents the end of the vector as
an untyped iterator.
rbegin
public ReverseRandomIterator rbegin()
- Returns a copy of the reverse iterator that represents the
beginning (end) of the list.
rend
public ReverseRandomIterator rend()
- Returns a copy of the iterator that represents the end (beginning)
of the list.
rbeginGeneric
public Iterator rbeginGeneric()
- Returns a copy of the reverse iterator that represents the
beginning (end) of the list as an untyped Iterator.
rendGeneric
public Iterator rendGeneric()
- Returns a copy of the iterator that represents the end (beginning)
of the list as an untyped Iterator.
size
public int size()
- Returns the number of elements stored in the vector.
max_size
public int max_size()
- Returns the maximum number of elements that can be stored in a vector.
capacity
public int capacity()
- Returns the maximum number of elements that can be stored in the vector
without reallocation.
empty
public boolean empty()
- Returns
true
if the vector does not contain any elements.
get
public Object get(int n)
- Returns the
n
th element in the container.
put
public Object put(int n,
Object o)
- Set the
n
th element in the container to o.
front
public Object front()
- Return the first element in the container.
back
public Object back()
- Return the last element in the container.
push_back
public void push_back(Object o)
- Add an element to the end of the vector.
insert
public Iterator insert(Iterator position,
Object o)
- Insert an element into the vector at the specified position.
Elements located after the position are moved.
- Parameters:
- position - insert the element at this position.
- o - the element to insert.
- Returns:
- An iterator to the position where the element was inserted.
insert
public void insert(Iterator position,
int n,
Object o)
- Insert n references to element into the vector at the specified position.
Elements located after the position are moved.
- Parameters:
- position - insert the element at this position.
- n - the number of elements to insert.
- o - the element to insert.
insert
public void insert(Iterator position,
InputIterator first,
InputIterator last)
- The elements in the range
[first,last)
are inserted
into vector at the
specified position.
Elements located after the position are moved.
- Parameters:
- position - insert the element at this position.
- first - the beginning of the range.
- last - the end of the range.
pop_back
public void pop_back()
- Removes the last element in vector.
erase
public void erase(Iterator position)
- Removes the element specified by position.
erase
public void erase(Iterator first,
Iterator last)
- Removes the elements in the specified range.
- Parameters:
- first - the beginning of the range.
- last - the end of the range.
toString
public String toString()
- Returns the string representation of this vector.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index